#Alexander F. Gazmararian
#afg2@princeton.edu
#January 9, 2024

#Purpose: Prepare data coal production data used in subsequent analyses

#Load packages
library(tidyverse)
library(tidylog)
library(readxl)
library(here)

# Load EIA coal data
g <- read_xls(here("data", "input", "eia_annualcoalreport/tableES1-3.xls"), skip = 3)
#rename variables
names(g) <- c("year", "bit", "sub", "lig", "ant", "underground", "surface", "east", "west", "total")
#remove extra information appendix to the bottom of the data frame
g$year <- as.numeric(g$year)
g <- filter(g, !is.na(year))
#convert to numeric--will produce some NAs
g <- mutate(g, across(everything(), ~ as.numeric(.x)))
#save processed EIA data
saveRDS(g, here("data", "input", "eia_annualcoalreport", "eia_annualcoalreport.rds"))